
local ui = class.select_panel.create('同步-选择符文')
ac['符文选择'] = ui
ui:set_level(99)
ui:set_select_button(3,class.card_data,300,429)
ui:hide()

for a,button in ipairs(ui.childs) do
    local x1,y1 = button:get_real_position()
    local y2 = y1 + (button.index%2==1 and 1 or -1)*200
    button.y1 = y1
    button.y2 = y2
end

--重置按钮
local refresh = ui:add_namebutton('刷新',(1920-300)/2,660,120,60,16,5)
ac.card_refresh = refresh

function refresh:on_button_clicked()
    ac.sync('同步-刷新符文')
end


--关闭
local esc = ui:add_namebutton('关闭',(1920-300)/2 + 180,660,120,60,16,5)

function esc:on_button_clicked()
    ui:hide()
end

function ui:update()
    local player = ac.player.self
    local hero = player.hero
    if self._tf_ani_timer then
        self._tf_ani_timer:remove()
        self._tf_ani_timer = nil
    end
    --动画
    local time = (self.wait_select - ac.clock()) / 1000
    for a,button in ipairs(self.childs) do
        if button:is_show() then
            if time>0 then
                button:set_real_position(button.x,button.y2)
                button:move_animation({button.x,button.y1},time)
            else
                button:set_real_position(button.x,button.y1)
            end
        end
    end
    if hero then
        local num = hero:get_data('免费刷新',0)
        local pay = hero:get_data('付费刷新',0)
        if num>0 then
            refresh.text:set_text(('刷新(|cff00ff00%0.f|r)'):format(num))
        elseif pay>0 then
            refresh.text:set_text(('刷新(|cffff0000%0.f|r)'):format(pay))
        else
            refresh.text:set_text(('刷新'):format(num))
        end

    end
end


function ui:on_button_clicked(button)
    if button.index and button.button_type=='选择按钮' and self.wait_select<ac.clock() then
        ac.sync(self.sync_name or self.name,button.index)

        --动画
        local time = 0.15
        for a,button in ipairs(self.childs) do
            if button:is_show() then
                button:set_real_position(button.x,button.y1)
                button:move_animation({button.x,button.y2},time)
            end
        end

        self._tf_ani_timer = ac.wait(time*1000,function()
            self._tf_ani_timer = nil
            self:hide()
        end)
    end 
end
